import { defineStore } from 'pinia'

export interface ScreenData {
  customer_province_dic: any[] // 省份里的客户数量分布
  dealer_province_dic: any[] // 省份里的经销商数量分布
  customer_type_dic: any[] // 客户分类数量分布
  instrument_category_dic: any[] // 实验仪器百科分类数量分布
  equipment_category_dic: any[] // 实验器材分类数量分布
  orders: any[] // 图表的数据项
  equipments: any[] // 图表的数据项
  dealers: any[] // 经销商数据
}

export const useScreenStore = defineStore('screen', {
  state: (): ScreenData => ({
    customer_province_dic: [],
    dealer_province_dic: [],
    customer_type_dic: [],
    instrument_category_dic: [],
    equipment_category_dic: [],
    orders: [],
    equipments: [],
    dealers: [],
  }),

  actions: {
    // 设置所有数据
    setScreenData(data: Partial<ScreenData>) {
      if (data.customer_province_dic)
        this.customer_province_dic = data.customer_province_dic
      if (data.dealer_province_dic)
        this.dealer_province_dic = data.dealer_province_dic
      if (data.customer_type_dic)
        this.customer_type_dic = data.customer_type_dic
      if (data.instrument_category_dic)
        this.instrument_category_dic = data.instrument_category_dic
      if (data.equipment_category_dic)
        this.equipment_category_dic = data.equipment_category_dic
      if (data.orders) this.orders = data.orders
      if (data.equipments) this.equipments = data.equipments
      if (data.dealers) this.dealers = data.dealers
    },

    // 单独设置各个数据项的方法
    setCustomerProvinceDic(data: any[]) {
      this.customer_province_dic = data
    },

    setDealerProvinceDic(data: any[]) {
      this.dealer_province_dic = data
    },

    setCustomerTypeDic(data: any[]) {
      this.customer_type_dic = data
    },

    setInstrumentCategoryDic(data: any[]) {
      this.instrument_category_dic = data
    },

    setEquipmentCategoryDic(data: any[]) {
      this.equipment_category_dic = data
    },

    setOrders(data: any[]) {
      this.orders = data
    },

    setEquipments(data: any[]) {
      this.equipments = data
    },

    setDealers(data: any[]) {
      this.dealers = data
    },
  },

  getters: {
    // 获取所有数据
    getAllData: (state): ScreenData => state,
  },
})
